Kanzi 3.9.10
kanzi::KeyEvent Class Reference

The KeyEvent holds a pressed, released, or auto-repeated key event that occurs in the host operating system. More...

#include <kanzi/core.ui/platform/input/common/events.hpp>

Inheritance diagram for kanzi::KeyEvent:
[legend]

Public Member Functions

LogicalKey getKey () const
 Returns the LogicalKey value of the key event.
 
KeyModifier getKeyAsModifier () const
 Returns the KeyModifier value of the key event LogicalKey value.
 
LogicalKey getKeyDown () const
 Returns the logical key value of the key event if the event is in pressed state.
 
size_t getKeyRepeatCount () const
 Returns the key-press repetition count.
 
LogicalKey getKeyUp () const
 Returns the logical key value of the key event if the event is in released state.
 
KeyModifier getModifiers () const
 Returns the modifiers bit fields of the key event.
 
size_t getRawKey () const
 Returns the operating system specific raw key code of the event.
 
KeyState getState () const
 Returns the state of the key event.
 
bool hasAltModifier () const
 Checks whether the key event has any of the Alt key modifiers set.
 
bool hasCapsLock () const
 Returns whether the key event is created with the KeyModifier::CapsLock modifier.
 
bool hasControlModifier () const
 Checks whether the key event has any of the Control key modifiers set.
 
bool hasModifier (KeyModifier modifier) const
 Checks whether the given modifier is set on the key event.
 
bool hasShiftModifier () const
 Checks whether the key event has any of the Shift key modifiers set.
 
bool hasSuperModifier () const
 Checks whether the key event has any of the Super key modifiers set.
 
bool isDown () const
 Returns true if the key event represents a key down status, meaning it has Pressed status.
 
bool isKeyModifier () const
 Checks whether the key of the event is a modifier key.
 
bool isTranslated () const
 Returns true if the key event holds a translated operating system key event.
 
bool isUp () const
 Returns true if the key event represents a key released status.
 
bool isValid () const
 Checks whether the key event is valid.
 
 KeyEvent (LogicalKey logicalKey, KeyModifier logicalKeyModifiers, KeyState keyState)
 Creates a key event with a logical key, logical key modifiers, and key state.
 
 KeyEvent (LogicalKey logicalKey, KeyModifier logicalKeyModifiers, size_t repeatCount)
 Creates a key-press repetition event with a logical key, logical key modifiers, and repetition count.
 
 KeyEvent (size_t rawKeyCode, KeyState keyState)
 Creates a key event with a raw key code and key state.
 
 KeyEvent (size_t rawKeyCode, LogicalKey logicalKey, KeyModifier logicalKeyModifiers, KeyState keyState)
 Creates a key event with a raw key code, logical key, logical key modifiers, and key state.
 
 KeyEvent (size_t rawKeyCode, LogicalKey logicalKey, KeyModifier logicalKeyModifiers, size_t repeatCount)
 Creates a key-press repetition event with a raw key code, logical key, logical key modifiers, and repetition count.
 
 KeyEvent (size_t rawKeyCode, size_t repeatCount)
 Creates a key-press repetition event with a raw key code and repetition count.
 
- Public Member Functions inherited from kanzi::InputEvent
Type getType () const
 Returns the type of the event.
 
 InputEvent (Type type)
 Constructs an event with a given type.
 
bool isHandled () const
 Returns true if the event is handled, false if not.
 
void markHandled ()
 Marks the event as handled.
 
virtual ~InputEvent ()
 Destructor.
 

Static Public Attributes

static const size_t InvalidRawKey
 Identifies an invalid raw key code.
 

Protected Member Functions

 KeyEvent ()
 Constructor. Creates an invalid key event.
 

Protected Attributes

bool m_capsLock
 The Caps lock state.
 
LogicalKey m_key
 The translated logical key code.
 
KeyModifier m_modifiers
 The key modifier flags applied on the key stroke.
 
size_t m_rawKeyCode
 The raw key code, an operating system specific value.
 
size_t m_repeatCount
 The key-press repetition count.
 
KeyState m_state
 The key event state.
 

Additional Inherited Members

- Public Types inherited from kanzi::InputEvent
enum  Type {
  Key , Pointer , Touch , WindowResized ,
  WindowResizeRequest , WindowFocusLost , WindowFocusGained , WindowHidden ,
  WindowResourcesLost , WindowOrientationChanged , WindowRedrawRequest , WindowPlacement ,
  WindowClosed , ApplicationPaused , ApplicationSleep , ApplicationWakeup ,
  DebugToggleHud , DebugSetHud , UserEvent
}
 InputEvent type enumeration. More...
 

Detailed Description

The KeyEvent holds a pressed, released, or auto-repeated key event that occurs in the host operating system.

The KeyEvent contains:

  • The raw key code. This code is operating system specific.
  • The logical key code translated from the raw key code.
  • The logical key modifiers.

Operating system adaptations can map the raw key code into a LogicalKey value and set the applicable key modifiers.

When the operating system key code does not match any logical key defined in Kanzi, create the key event with the raw key code set. When you create a KeyEvent in this way, you tell Kanzi that the raw key code is the only valid information when handling the event.

If the application does not detect any key modifiers or the modifier presented by the operating system does not match any modifier defined by Kanzi, set KeyModifier::Undefined.

The type of the event is InputEvent::Key.

Constructor & Destructor Documentation

◆ KeyEvent() [1/7]

kanzi::KeyEvent::KeyEvent ( LogicalKey logicalKey,
KeyModifier logicalKeyModifiers,
KeyState keyState )
explicit

Creates a key event with a logical key, logical key modifiers, and key state.

The raw key code of the key event that you create this way is set to 0.

Parameters
logicalKeyThe logical key code of the event.
logicalKeyModifiersThe logical key modifiers that accompany the key event.
keyStateThe key state.

◆ KeyEvent() [2/7]

kanzi::KeyEvent::KeyEvent ( size_t rawKeyCode,
KeyState keyState )
explicit

Creates a key event with a raw key code and key state.

Use this constructor when the raw key code does not map to any logical key code defined in Kanzi.

Parameters
rawKeyCodeThe operating system specific raw key code.
keyStateThe key state.

◆ KeyEvent() [3/7]

kanzi::KeyEvent::KeyEvent ( size_t rawKeyCode,
LogicalKey logicalKey,
KeyModifier logicalKeyModifiers,
KeyState keyState )
explicit

Creates a key event with a raw key code, logical key, logical key modifiers, and key state.

Kanzi preserves the raw key code of the created key event.

Parameters
rawKeyCodeThe operating system specific raw key code.
logicalKeyThe logical key code of the event. If the raw key code is not translated to a logical key, use LogicalKey::Unknown.
logicalKeyModifiersThe logical key modifiers that accompany the key event. If the raw key code is not translated to a logical key, use KeyModifier::Undefined.
keyStateThe key state.
Since
Kanzi 3.9.8

◆ KeyEvent() [4/7]

kanzi::KeyEvent::KeyEvent ( LogicalKey logicalKey,
KeyModifier logicalKeyModifiers,
size_t repeatCount )
explicit

Creates a key-press repetition event with a logical key, logical key modifiers, and repetition count.

Parameters
logicalKeyThe logical key code of the event.
logicalKeyModifiersThe logical key modifiers that accompany the key event.
repeatCountThe number of key press repetitions.

◆ KeyEvent() [5/7]

kanzi::KeyEvent::KeyEvent ( size_t rawKeyCode,
size_t repeatCount )
explicit

Creates a key-press repetition event with a raw key code and repetition count.

Parameters
rawKeyCodeThe operating system specific raw key code.
repeatCountThe number of key press repetitions.

◆ KeyEvent() [6/7]

kanzi::KeyEvent::KeyEvent ( size_t rawKeyCode,
LogicalKey logicalKey,
KeyModifier logicalKeyModifiers,
size_t repeatCount )
explicit

Creates a key-press repetition event with a raw key code, logical key, logical key modifiers, and repetition count.

Parameters
rawKeyCodeThe operating system specific raw key code.
logicalKeyThe logical key code of the event.
logicalKeyModifiersThe logical key modifiers that accompany the key event.
repeatCountThe number of key press repetitions.
Since
Kanzi 3.9.8

◆ KeyEvent() [7/7]

kanzi::KeyEvent::KeyEvent ( )
explicitprotected

Constructor. Creates an invalid key event.

Member Function Documentation

◆ isValid()

bool kanzi::KeyEvent::isValid ( ) const

Checks whether the key event is valid.

A key event is valid if it has either the operating system specific raw key code or the LogicalKey value set.

Returns
If the key event is valid, true, otherwise false.
Since
Kanzi 3.9.0

◆ getRawKey()

size_t kanzi::KeyEvent::getRawKey ( ) const
inline

Returns the operating system specific raw key code of the event.

If the event was created without a raw key code, returns 0.

◆ getKey()

LogicalKey kanzi::KeyEvent::getKey ( ) const
inline

Returns the LogicalKey value of the key event.

◆ getModifiers()

KeyModifier kanzi::KeyEvent::getModifiers ( ) const
inline

Returns the modifiers bit fields of the key event.

Since
Kanzi 3.8.0 returns KeyModifier.

◆ getState()

KeyState kanzi::KeyEvent::getState ( ) const
inline

Returns the state of the key event.

See also
State

◆ isDown()

bool kanzi::KeyEvent::isDown ( ) const
inline

Returns true if the key event represents a key down status, meaning it has Pressed status.

See also
State

◆ isUp()

bool kanzi::KeyEvent::isUp ( ) const
inline

Returns true if the key event represents a key released status.

◆ hasModifier()

bool kanzi::KeyEvent::hasModifier ( KeyModifier modifier) const
inline

Checks whether the given modifier is set on the key event.

Returns
true if the modifier is set, false otherwise.

◆ isKeyModifier()

bool kanzi::KeyEvent::isKeyModifier ( ) const

Checks whether the key of the event is a modifier key.

Returns
If the key is a modifier key, returns true, otherwise false.
Since
Kanzi 3.9.0

◆ getKeyAsModifier()

KeyModifier kanzi::KeyEvent::getKeyAsModifier ( ) const

Returns the KeyModifier value of the key event LogicalKey value.

Returns
The KeyModifier value of the key event LogicalKey value. If the LogicalKey value is not a key modifier, returns KeyModifier::Undefined.
Since
Kanzi 3.9.4

◆ getKeyDown()

LogicalKey kanzi::KeyEvent::getKeyDown ( ) const
inline

Returns the logical key value of the key event if the event is in pressed state.

Returns
The logical key value if pressed, KeyMax if the key is not pressed.

◆ getKeyRepeatCount()

size_t kanzi::KeyEvent::getKeyRepeatCount ( ) const
inline

Returns the key-press repetition count.

Returns
The key-press repetition count. If the key is not pressed, returns 0u.
Since
Kanzi 3.9.0

◆ getKeyUp()

LogicalKey kanzi::KeyEvent::getKeyUp ( ) const
inline

Returns the logical key value of the key event if the event is in released state.

Returns
The logical key value if released, KeyMax if the key is not in released state.

◆ isTranslated()

bool kanzi::KeyEvent::isTranslated ( ) const

Returns true if the key event holds a translated operating system key event.

◆ hasShiftModifier()

bool kanzi::KeyEvent::hasShiftModifier ( ) const

Checks whether the key event has any of the Shift key modifiers set.

Returns
If the key event has one of the Shift modifiers set, true, otherwise false.
See also
KeyModifier

◆ hasAltModifier()

bool kanzi::KeyEvent::hasAltModifier ( ) const

Checks whether the key event has any of the Alt key modifiers set.

Returns
If the key event has one of the Alt modifiers set, true, otherwise false.
See also
KeyModifier

◆ hasControlModifier()

bool kanzi::KeyEvent::hasControlModifier ( ) const

Checks whether the key event has any of the Control key modifiers set.

Returns
If the key event has one of the Control modifiers set, true, otherwise false.
See also
KeyModifier

◆ hasSuperModifier()

bool kanzi::KeyEvent::hasSuperModifier ( ) const

Checks whether the key event has any of the Super key modifiers set.

Returns
If the key event has one of the Super modifiers set, true, otherwise false.
See also
KeyModifier

◆ hasCapsLock()

bool kanzi::KeyEvent::hasCapsLock ( ) const
inline

Returns whether the key event is created with the KeyModifier::CapsLock modifier.

Returns
If the key event is created with the KeyModifier::CapsLock modifier, true, otherwise false.
Since
Kanzi 3.9.0

Member Data Documentation

◆ InvalidRawKey

const size_t kanzi::KeyEvent::InvalidRawKey
static

Identifies an invalid raw key code.

Since
Kanzi 3.9.8

◆ m_rawKeyCode

size_t kanzi::KeyEvent::m_rawKeyCode
protected

The raw key code, an operating system specific value.

If you create the event with no raw key code, this value is 0.

◆ m_repeatCount

size_t kanzi::KeyEvent::m_repeatCount
protected

The key-press repetition count.

Since
Kanzi 3.9.0

◆ m_modifiers

KeyModifier kanzi::KeyEvent::m_modifiers
protected

The key modifier flags applied on the key stroke.

◆ m_key

LogicalKey kanzi::KeyEvent::m_key
protected

The translated logical key code.

◆ m_state

KeyState kanzi::KeyEvent::m_state
protected

The key event state.

◆ m_capsLock

bool kanzi::KeyEvent::m_capsLock
protected

The Caps lock state.


The documentation for this class was generated from the following file: